package com.rawchen.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @Description: 封装响应结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
	private Integer code;
	private String msg;
	private Object data;

	private Result(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static Result ok(String msg, Object data) {
		return new Result(HttpStatus.OK.value(), msg, data);
	}

	public static Result ok(String msg) {
		return new Result(HttpStatus.OK.value(), msg);
	}

	public static Result error(String msg) {
		return new Result(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
	}

	public static Result error() {
		return new Result(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
	}

	public static Result create(Integer code, String msg, Object data) {
		return new Result(code, msg, data);
	}

	public static Result create(Integer code, String msg) {
		return new Result(code, msg);
	}
}
